package com.platform.auth.api;

import com.platform.auth.dto.PermissionDTO;
import com.platform.common.constant.RedisConstants;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/internal/auth")
public interface PermissionApi {
    String SERVICE_NAME = "auth-service";

    /**
     * @description 同步微服务 URL 到权限中心
     */
    @PostMapping(value = "/sync", consumes = "application/json")
    void sync(@RequestBody List<PermissionDTO> permissionDTOList);

    /**
     * @description 查询所有url权限信息
     */
    @GetMapping(value = "/listAll")
    @Cacheable(value = RedisConstants.ALL_URL_PERMISSION)
    List<PermissionDTO> listAll();

    @GetMapping(value = "/queryUrlToRolesMap")
    @Cacheable(value = RedisConstants.URL_TO_ROLES_MAP)
    Map<String, List<String>> queryUrlToRolesMap();

    @GetMapping(value = "/urlToRoles")
    @Cacheable(key = "#url", value = RedisConstants.URL_TO_ROLES)
    List<String> urlToRoles(@RequestParam("url") String url);
}